This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
Efficient MXNet sampling in the multinomial distribution #15311
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR has solved the problem of low efficiency to sample from the multinomial distribution, especially the distribution with a large number of possible outcomes. As it was described in #15231, it costs ~44 s using
mx.nd.random.multinomial
, whilenp.random.multinomial
costs ~0.019 s. After our optimization, it decreases to ~0.054 s.Feature changes
New features
double
type to define some cumulative variables for high precision with very small probabilities.Performance
We compared the time costs of
mx.nd.random.multinomial
on branch master(b8b352d) and our PR shown in the table below. The result shows that the time cost of the original sampling strategy rises much more rapidly than that of our PR with the increasing number of outcomes.Comments
@pengzhao-intel @ciyongch @TaoLv Please help me refine this PR and have some review on it. Thanks.
Check list